package work

import "github.com/zeromicro/go-zero/core/syncx"

type Work struct {
	barrier syncx.SingleFlight
}

func (w *Work) Do(key string, fn func() (any, error)) error {
	_, err := w.barrier.Do(key, fn)
	return err
}

func NewWork() Work {
	return Work{
		barrier: syncx.NewSingleFlight(),
	}
}
